#include "main/utils.h"
using namespace std;

bool isSort(const vector<string> &vec, const string &order) {
  vector<int> help_order(26, 0);
  for (int i = 0; i < order.size(); ++i) {
    help_order[order[i] - 'a'] = i;
  }
  auto compare = [&](const string& a, const string &b) {
    int min_length = a.size() < b.size() ? a.size() : b.size();
    for (int i = 0; i < min_length; ++i) {
      if (help_order[a[i] - 'a'] < help_order[b[i] - 'a']) {
        return true;
      } else if (help_order[a[i] - 'a'] > help_order[b[i] - 'a']) {
        return false;
      }
    }
    return a.size() < b.size();
  };

  for (int i = 0; i < vec.size() - 1; ++i) {
    if (!compare(vec[i], vec[i + 1])) {
      return false;
    }
  }
  return true;
}

int main() {
  string order = "zyxwvutsrqponmlkjihgfedcba";
  vector<string> vec = {"offer", "is", "coming"};
  bool ret = isSort(vec, order);
  cout << ret << endl;

  return 0;
}
